<?php
mysql_connect("localhost", "", "");
mysql_query("USE stats_syslog");

for ($month=12; $month<=12; $month++) {
	for ($day=13; $day<=16; $day++) {

		$date = sprintf("%04d-%02d-%02d", 2007, $month, $day);
		$query = "select Cluster, Reason, COUNT(*) AS number FROM maillog WHERE timestamp>='$date' AND timestamp<='$date 23:59:59' GROUP BY Cluster, Reason";
		$result = mysql_query($query);
		$numrows = mysql_num_rows($result);

		for ($count=0; $count<$numrows; $count++) {
			$Cluster = mysql_result($result, $count, Cluster);
			$Reason = mysql_result($result, $count, Reason);
			$number = mysql_result($result, $count, number);
			$query = "insert into reasons_all values ('$date', '$Cluster', '$Reason', '$number')";
			mysql_query($query);
		}

		print "$date<BR>";
	}
}

mysql_close();
?>
